package com.YKFuse.wrapper.calculate;

import com.YKFuse.bean.operation.pool.YKFusePoolOperation;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Method;
import java.util.Set;

import static com.YKFuse.util.BeanUtil.copyBeanProperties;

/**
 * @author yuank
 * @version 1.0.0
 * @date 2025/2/17 14:09:09
 */
public class BeanMethodCalculateProxyFactory {

    public static <T> T createProxy(Object bean, Set<Method> methods, YKFusePoolOperation YKFusePoolOperationImpl) throws NoSuchFieldException, IllegalAccessException {
        final Class<?> aClass = bean.getClass();
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(aClass);
        enhancer.setCallback(new BeanMethodCalculateProxy(bean, methods, YKFusePoolOperationImpl));
        final T t = (T) enhancer.create();
        // 将原始对象的字段值复制到代理对象上
        copyBeanProperties(bean, t);
        return t;
    }
}